package com.app.shop.config;


import com.app.shop.util.ApiRest;
import com.app.shop.util.Constant;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * GlobalExceptionHandlerAdvice 统一异常处理
 * @author chenliwei
 * @version 1.0 2017-11-5
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    private final static Log logger = LogFactory.getLog(GlobalExceptionHandler.class);
    /**
     * 全局异常捕捉处理
     * @param ex 全局异常参数
     * @return 返回异常页面
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ApiRest errorHandlerAll(Exception ex) {
        logger.error(ExceptionUtils.getStackTrace(ex));
        return new ApiRest(Constant.REST_ERROR_CODE, ex.getMessage());
    }


}